import Vue from 'vue'
import VueRouter from 'vue-router'
import ManagerView from "@/views/ManagerView";
import MuserView from "@/views/MuserView";
import MapView from "@/views/MapView";
import LoginView from "@/views/LoginView";
import RegisterView from "@/views/RegisterView";
import AdminView from "@/views/AdminView";
import DriverView from "@/views/DriverView";
import OrderView from "@/views/OrderView";
import CarView from "@/views/CarView";
import StationView from "@/views/StationView";
import StandardView from "@/views/StandardView";
import FinanceView from "@/views/FinanceView";
import TransView from "@/views/TransView";
import UserView from "@/views/UserView";
import EmployeeView from "@/views/EmployeeView";
import MyView from "@/views/MyView";
import PackageView from "@/views/PackageView";
import MyMapView from "@/views/MyMapView";
import MyStationView from "@/views/MyStationView";
import EmployeeInfoView from "@/views/EmployeeInfoView";
import EmployeeBagView from "@/views/EmployeeBagView";
import EmployeeGPS from "@/views/EmployeeGPS";
import EmployeeStation from "@/views/EmployeeStation";
import ManagerMain from "@/views/ManagerMain";
import UserMain from "@/views/UserMain";
import EmployeeMain from "@/views/EmployeeMain";
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Index',
    redirect:{name:"登录"}
  },
  {
    path: '/login',
    name: '登录',
    component: LoginView
  },
  {
    path: '/register',
    name: '注册',
    component: RegisterView
  },
  {
    path: '/user',
    name: '用户界面',
    component: UserView,
    redirect:{name:"用户界面"},
    children: [
      {
        path: '/user/main',
        name: '用户界面',
        component:UserMain
      },
      {
        path: '/user/me',
        name: '我的',
        component: MyView
      },
      {
        path: '/user/package',
        name: '包裹',
        component: PackageView
      },
      {
        path: '/user/map',
        name: '快递物流',
        component: MyMapView
      },
      {
        path: '/user/station',
        name: '附近站点(用户)',
        component: MyStationView
      }
    ]
  },
  {
    path: '/employee',
    name: '员工界面',
    component: EmployeeView,
    redirect:{name:"员工主界面"},
    children: [
      {
        path:'/employee/receipt',
        name: '级联',
        component: RegisterView
      },
      {
        path: '/employee/main',
        name: '员工主界面',
        component: EmployeeMain
      },
      {
        path: '/employee/me',
        name: '员工个人信息',
        component: EmployeeInfoView
      },
      {
        path: '/employee/package',
        name: '待送快递',
        component: EmployeeBagView
      },
      {
        path:'/employee/GPS',
        name: 'GPS',
        component: EmployeeGPS

      },
      {
        path: '/employee/station',
        name: '附近站点(员工)',
        component: EmployeeStation
      }
    ]
  },
  {
    path: '/manager',
    name: '管理员页面',
    component: ManagerView,
    redirect:{name:"管理员主界面"},
    children: [
      {
        path: '/manager/main',
        name: '管理员主界面',
        component: ManagerMain
      },
      {
          path: '/manager/admin',
          name: '管理员列表',
          component: AdminView
      },
      {
        path: '/manager/user',
        name: '用户列表',
        component: MuserView
      },
      {
        path: '/manager/driver',
        name: '快递员工',
        component: DriverView
      },
      {
        path: '/manager/orders',
        name: '订单显示',
        component: OrderView
      },
      {
        path: '/manager/map',
        name: '地图显示',
        component: MapView
      },
      {
        path: '/manager/car',
        name:'车辆详情',
        component: CarView
      },
      {
        path: '/manager/station',
        name: '仓库/站点',
        component: StationView
      },
      {
        path: '/manager/standard',
        name: '计价规则',
        component: StandardView
      },
      {
        path: '/manager/finance',
        name: '收入',
        component: FinanceView
      },
      {
        path: '/manager/trans',
        name: '运输',
        component: TransView
      }
    ]

  }



  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
]

const router = new VueRouter({
  mode:'history',
  routes

})

router.beforeEach((to,from,next)=>{
  // console.log(to,from)
  // if(to.name==='xinwen' || to.name==='xiaxoi') 这种写法也可以
  if(to.path ==='/manager' || to.path ==='/employee'||to.path==='/user'){
    if(localStorage.getItem('userInfo' ) === null ){
      next()
    }else{
      alert('无法访问')
    }
  }else{
    next()
  }


})


export default router
